<template>
  <div class="template-index-Lu">
    <commpVxeTable
          :isCanWrap="true"
          :conditionBtnRow="true"
          :key="reCommpVxeTable"
          :config="dataTableConfig"
          :columns="columnsVxe"
          :formItem="formItem"
          @checkboxChange="checkboxChange"
          ref="administrativeOffice"
          @searchEvent="searchEvent"
          @resetEvent="resetEvent"
          >
          <template v-slot:externalOperations="{data}"  >
              <vxe-form-item>
                  <template>
                      <a-button class="blue-btn" @click="reviseClick({},false)" icon="plus">新增技术职称</a-button>
                  </template>
              </vxe-form-item>
          </template>
        <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
              <a-form layout="inline">
                  <a-form-item>
                      <a-button class="green-btn" @click="reviseClick(row,true)" icon="eye">查看</a-button>
                  </a-form-item>
                  <a-form-item>
                      <a-button class="blue-btn" @click="reviseClick(row,false)" icon="edit">编辑</a-button>
                  </a-form-item>
                  <a-form-item>
                    <a-button class="red-btn" @click="deletehandle(row)" icon="delete">删除</a-button>
                  </a-form-item>
              </a-form>
          </template>
      </commpVxeTable>
      <increase ref="increaseRef" @success="success"></increase>
  </div>
</template>
<script>
import  commpVxeTable   from '@/components/commp-vxe-table/commp-vxe-table.vue'
import  assessCheckApi  from './service/api'
import increase from './increase.vue'
import { deleteDwk } from './service/index'
export default {
  components: {
      commpVxeTable,increase
  },
  data() {
    return {
          reCommpVxeTable: '',
          dataTableConfig: {
              api: assessCheckApi.pageList,
              rowId: 'id',
              paramet: {}
          },
          columnsVxe: [
              {
                  type: 'checkbox',
                  width: 60,
                  fixed: 'left'
              },{
                  title: '序号',
                  field: 'forder',
                  width: 50,
              },{
                  title: '单位全称',
                  field: 'fdwqc',
              },{
                  title: '单位地址',
                  field: 'fdwdz',
              },{
                  title: '单位类型',
                  field: 'fdwlx',
              },{
                  title: '是否药检所',
                  field: 'fsfyjs',
                  width: 100,
              },{
                  title: '所属地市',
                  field: 'fssds',
                  width: 100,
              },{
                  title: '操作',
                  field: 'jobid',
                  fixed: 'right',
                  width: 280,
                  titleInterval:true,
                  slots: {
                  // 使用插槽模板渲染
                      header:'data2_header',
                      default: 'operation_btn',
                  },
              }
          ],
          formItem: [
              {
                  label: '单位全称',
                  model: 'fdwqc',
              },{
                  label: '单位地址',
                  model: 'fdwdz',
              },{
                  label: '单位类型',
                  model: 'fdwlx',
              },{
                  label: '是否药检所',
                  model: 'fsfyjs',
                  type:'Select',
                  options:[{
                    label:'是',
                    value:'是'
                  },{
                    label:'否',
                    value:'否'
                  }]
              },{
                  label: '所属地市',
                  model: 'fssds',
              },
          ],
          idList: [],
          formData: {},
      }
  },
  methods: {
      // 勾选
      checkboxChange(val){
          //console.log('已选择',val)
          this.idList = []
          if(val.length){
              val.forEach(item => {
                  this.idList.push(item.id)
              });
          }
      },
      // 搜索
      searchEvent(){
          this.dataTableConfig.paramet = {
              ...this.dataTableConfig.paramet,
          }
      },
      // 重置
      resetEvent(){
          //console.log('重置')
          this.reCommpVxeTable = Date.now()
          this.dataTableConfig.paramet = {
              ...this.dataTableConfig.paramet,
          }
      },
      reviseClick(row,isview){
        //console.log(row)
        this.$nextTick(() => {
          this.$refs.increaseRef.getData(row,isview)
          this.$refs.increaseRef.increaseVisible = true
        })
      },
      deletehandle(row){
        var that = this
        that.$confirm({
          title: '您确定要删除当前技术职称吗?',
          content: '',
          okText: '确定',
          okType: 'danger',
          cancelText: '取消',
          onOk() {
            deleteDwk({id: row.id}).then(res => {
              //console.log(res)
              if(res.code == 200){
                that.reCommpVxeTable = Date.now()
                that.$message.success(res.message)
              } else {
                that.$message.warning(res.message)
              }
            })
          },
          onCancel() {
            //console.log('Cancel');
          },
        });
      },
    // 弹窗关闭
    success(){
      // 刷新表格 清空id数组
      this.$refs.administrativeOffice.resetEvent()
      this.idList = []
    },
  },
}
</script>
